#include <stdio.h>

const int  Num=10000000;

int formatInt(float f){
    int tmp=(int)f;
    int end=(f-tmp)>=0.5f?1:0;
    return tmp+end;
}

int main(){
    int x,y;
    float z,t,v;
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d %f",&x,&y,&z);
        if(y<x)
        {
            x+=24;
        }
        t=(y-x)*60.0f;
        v=z/t;
        float result=0;

        if(t<=z)
        {
            result=1;
        }
        else if(t<=2*z) //v>=0.5
        {
            result=(2*v-1)+(v+1)*(1-v); // 0+3/4
        }
        else{   //v<0.5
            result=3*v*v+2*v*(1-2*v);  // 3/4+0
        }

        result*=Num;
        int tmp=formatInt(result);
        result=1.0f*tmp/Num;
        printf("%1.7f\n",result);
    }
    return 0;
}